public class Solution {
    public int findMaxConsecutiveOnes(int[] nums) {
        int ans = 0;
        int cnt = 0;
        for (int x : nums) {
            if (x == 0) {
                cnt = 0; // 重置
            } else {
                cnt++; // 连续 1 的个数增加
                ans = Math.max(ans, cnt); // 更新答案的最大值
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1, 1, 0, 1, 1, 1};
        int result = solution.findMaxConsecutiveOnes(nums);
        System.out.println("最大连续1的个数为：" + result);
    }
}
